package com.quancheng.component.requestformat.config;

import com.quancheng.component.requestformat.filter.ParamShapingFilter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author zhouchaoqun
 * @email zhouchaoqun@quancheng-ec.com
 * @created 2018/2/7 上午9:28
 */
@Configuration
@ConditionalOnProperty(name = "mvc.config.param.shaping", havingValue = "true")
public class ParamShapingConfig {

    @Value("${mvc.config.param.shaping.uris}")
    private String paramShapingUrls;

    @Bean
    public FilterRegistrationBean paramShapingFilter() {
        FilterRegistrationBean paramShapingFilter = new FilterRegistrationBean();
        String[] uris = paramShapingUrls.split(",");
        paramShapingFilter.addUrlPatterns(uris);
        paramShapingFilter.setFilter(new ParamShapingFilter());
        return paramShapingFilter;
    }
}
